<template>
	<view class="content" style="background-color: #f5f5f5;">
		<u-navbar scrollable=false titleStyle="font-size:40rpx;color:#333" :placeholder='true' title="实名认证"
			:autoBack="true">
		</u-navbar>

		<view class="tip co3 fontS28">
			{{isshow?'您已实名认证成功':'为了您的账户安全，请完成实名认证！'}}
		</view> 
		<view class="form">
			<view class="li">
				<text class="fw4" style="width: 40%;">真实姓名 <text class="homeRed">*</text> </text><input v-model="name" :disabled="isshow" type="text" class="input" placeholder="请输入" name="" id="">
			</view>
			<view class="li">
				<text class="fw4" style="width: 40%;">身份证号 <text class="homeRed">*</text> </text><input v-model="idCard" :disabled="isshow" type="text" class="input" placeholder="请输入" name="" id="">
			</view>
			<!-- <view class="li">
				<text class="fw4">手机号 <text class="homeRed">*</text> </text><input type="text" class="input" placeholder="请输入" name="" id="">
			</view> -->
		</view>
		<view class="paddingLR24" style="margin-top: 200rpx;">
			<u-button :loading='loading' class="redbtn btn bgcred cof fontS32 "   @click="submit" v-if="!isshow">
				提交
			</u-button> 
			<view class="center cof btn1" v-else>
				已实名
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				isshow:uni.getStorageSync('userInfo').card_id , //是否实名认证
				loading:false,
				name:uni.getStorageSync('userInfo').real_name,
				idCard:'',
			}
		},
		onLoad() {
			this.idCard=uni.getStorageSync('userInfo').card_id?uni.getStorageSync('userInfo').card_id:'';
			if(this.idCard){
				this.idCard=String(this.idCard.slice(0,1)) +'****************' + String(this.idCard.slice(17,18))
			}
			if(this.name){
				this.name=this.name.slice(0,1)
				let le=this.name.length
				for(var i =0 ; i<=le;i++){
					this.name+='*'
				}
			}
		},  
		methods: {
			submit(){
				if( (!this.name) || (!this.idCard)){
					this.$my.toast('请先完成表单')
				}else{
					this.loading=true;
					this.$my.post('/index/user/update_real_auth',{real_name:this.name,card_id:this.idCard}).then(res=>{
						 this.loading=false
						 this.$my.toast(res.message)
						 if(res.code==200){
							 // 获取用户个人信息
							 this.$my.get('/index/user/get_user_info').then(res=>{
							 	if(res.code==200){
							 	   uni.setStorageSync('userInfo',res.data)
							 	}
							 })
							 this.$my.go('',500)
						 }
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		// border: 2rpx solid #f5f5f5;
			.tip{
				padding: 30rpx 4% 10rpx;
				// line-height: 30rpx;
				background-color: white;
			}
			.form{
					background-color: white;
				.li{
					display: flex;
					margin: 0 4% 0;
					// padding-bottom: 20rpx;
					height: 100rpx;
					line-height: 100rpx;
					justify-content: space-between;
					border-bottom: 2rpx solid #f6f6f6;
					.input{
						text-align: right;
						line-height: 100rpx;
						height: 100rpx;
					}
				}
			}
			.btn1 {
				border-radius: 46rpx;
				margin: 200rpx 4% 0;
				height: 80rpx;
				line-height: 80rpx;
				background-color: #ccc;
				color: white;
				font-weight: bold;
			}
	}
</style>
